package com.otojob.controller;

import com.otojob.dto.PageDto;
import com.otojob.service.JobService;
import com.otojob.utils.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @Description
 * @Author: TingFeng
 * @CreateTime: 2022/5/17  19:32
 */
@RestController
@Api(value = "HomeController", tags = "主页")
@CrossOrigin
@RequestMapping("/home")
@Slf4j
public class HomeController {
    @Autowired
    private JobService jobService;
    @Resource
    private HttpServletRequest request;


    @ApiOperation("投递简历")
    @GetMapping("/sendResume")
    public Results sendResume(@NotNull
                              @Min(0)
                              @RequestParam("jobId") Integer jobId){
        return jobService.sendResume(jobId);
    }
    @ApiOperation("查询所有职位")
    @GetMapping("/findAllJobList")
    public Results findAllJobList(@Valid PageDto pageDto) {
        Results allJobList = jobService.findAllJobList(pageDto);
        return allJobList;
    }
    @ApiOperation("模糊查询带分页")
    @GetMapping("/searchByConditions")
    public Results searchByConditions(@Valid PageDto pageDto,String condition){
        log.info("num"+pageDto.getPageNum()+"size"+pageDto.getPageSize()+condition);
        return jobService.searchByConditions(pageDto,condition);
    }

    @ApiOperation("查询职位详情")
    @GetMapping("/findJobDetails")
    public Results findJobDetails(Integer id){
        return jobService.findJobDetails(id);
    }

    @ApiOperation("根据分类职位名称查询职位")
    @GetMapping("/findJobByJob")
    public Results findJobByJob(@Valid PageDto pageDto, String condition){
        log.info("num"+pageDto.getPageNum()+"size"+pageDto.getPageSize()+condition);
        return jobService.searchByConditions(pageDto,condition);

    }
}
